<template>
  <div>
    玩家操作
    <br />
    <a-button-group>
      <a-button @click="moveshang">上</a-button>
      <a-button @click="movexia">下</a-button>
      <a-button @click="movezuo">左</a-button>
      <a-button @click="moveyou">右</a-button>
    </a-button-group>

    <a-button-group>
      <a-button @click="suoxiao">缩小</a-button>
      <a-button @click="fangda">放大</a-button>
    </a-button-group>
    <br />
    重量 : {{ zhongliang }} 克
    <br />
    {{ zhongliang / 1000 }} 千克
    <br />
    {{ zhongliang / 1000000 }} 吨
    <br />
    <br />
    吞噬次数: {{ cishu }}
    <br />
    分裂次数: {{ fenlie }}
    <br />
    <br />

    <a-button @click="jianshaozhongliang">分裂</a-button>
    <a-button @click="zengjiazhongliang">吞噬</a-button>
    <a-button @click="chongzhi">重置重量,次数</a-button>

    <br />
    <br />
    <a-button type="danger" @mousedown="boom" @mouseup="boomup">爆炸</a-button>

    <br>  
    <br>  
    分数: {{fenhsu}}
  </div>
</template>
<script>
// var game from '';
import game from "../game";
import config from "../config";

export default {
  data() {
    return {
      zhongliang: config.player.init_weight,
      cishu: 0,
      fenlie: 0,
    };
  },
  computed:{
    fenhsu(){
      return window.statistical.star + 1 ;
    }
  },
  methods: {
    moveshang() {
      console.log("moveshang");
      window.player.y -= 50;
    },
    movexia() {
      window.player.y += 50;
    },
    movezuo() {
      window.player.x -= 50;
    },
    moveyou() {
      window.player.x += 50;
    },
    suoxiao() {
      this.zoom((window.player.scale.x += -0.1));
    },
    fangda() {
      this.zoom((window.player.scale.x += 0.1));
    },
    zoom(zom) {
      
      let jishu = 14.7;
      let arr = [jishu*zom,-((jishu * zom  )-jishu),-((jishu * zom)-jishu)];
      // console.log(arr)
      window.player.body.setCircle(arr[0],arr[1],arr[2]);
      window.player.scale.y = window.player.scale.x = zom;
      console.log("player zoom ", zom,arr);
    },
    zengjiazhongliang() {
      this.cishu++;
      this.zhongliang += this.zhongliang ;
    },
    jianshaozhongliang() {
      this.fenlie++;
      this.zhongliang -= this.zhongliang / 2;
    },
    chongzhi() {
      this.cishu = 0;
      this.fenlie = 0;
      this.zhongliang = config.player.init_weight;
    },
    boom() {
      // 玩家爆炸
      console.log("boom");
      // unfollow
      window.boom = {
        x: game.camera.x,
        y: game.camera.y,
      };
    },
    boomup() {
      window.boom = null;
    },
  },
  watch: {
    zhongliang(newvar) {
      let zom = Math.pow(newvar, 1 / config.player.pow);
      window.player.zom = zom;
      this.zoom(zom);
      // console.log(arguments)
    },
  },
};
</script>
<style>
</style>
